<?php

namespace App\Models\Business;

use App\Models\Config as ConfigModel;
// use App\Models\Product\Product as ProductModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
// use Illuminate\Database\Eloquent\SoftDeletes;

class Collection extends Model
{
    use HasFactory;

    // use SoftDeletes;

    protected $table = 'business_collection';

    // 自动写入时间戳
    public $timestamps = true;

    // 时间类型
    protected $dateFormat = 'U';

    // 自定义创建时间字段
    const CREATED_AT = 'createtime';

    // 自定义更新时间字段
    const UPDATED_AT = null;
    
    protected $guarded = [];

    protected $appends = [
        'thumb_cdn'
    ];

    public function getThumbCdnAttribute()
    {
        $cdn = ConfigModel::where('name','url')->value('value');

        $url = $cdn . '/shop/product/product/thumb';

        $thumb = httpRequest($url,['proid' => $this->proid]);

        return $thumb;
    }

    public function product()
    {
        // return 1111;
        // return $this->belongsTo('app\Models\Product\Product', 'id', 'proid', [], 'LEFT')->setEagerlyType(0);
        return $this->belongsTo('App\Models\Product\Product', 'proid', 'id');
    }
}
